<?php
/*********************************************************************************
 * Copyright (C) 2011-2013 X2Engine Inc. All Rights Reserved.
 * 
 * X2Engine Inc.
 * P.O. Box 66752
 * Scotts Valley, California 95067 USA
 * 
 * Company website: http://www.x2engine.com 
 * Community and support website: http://www.x2community.com 
 * 
 * X2Engine Inc. grants you a perpetual, non-exclusive, non-transferable license 
 * to install and use this Software for your internal business purposes.  
 * You shall not modify, distribute, license or sublicense the Software.
 * Title, ownership, and all intellectual property rights in the Software belong 
 * exclusively to X2Engine.
 * 
 * THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT WARRANTIES OF ANY KIND, EITHER 
 * EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED WARRANTIES OF 
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE, AND NON-INFRINGEMENT.
 ********************************************************************************/
 
$attributeLabels = $model->attributeLabels();

$parts = explode('.',$model->fileName);			// split filename on '.'

$file = Yii::app()->file->set('uploads/'.$model->fileName);

$file_ext = strtolower($file->getExtension());	// extension is the last part

$legal_extensions = array('jpg','gif','png','bmp','jpeg','jpe');

$fileView = '';
$fileURL = Yii::app()->request->baseUrl.'/uploads/'.urlencode($model->fileName);
if(in_array($file_ext,$legal_extensions))
	$fileView .= CHtml::link(CHtml::image($fileURL,'',array('class'=>'attachment-img')),$fileURL);
?>
<div class="form no-border" style="margin:0;">
<table class="details">
	<?php if(!empty($fileView)) { ?>
		<tr>
			<td colspan="4">
				<?php echo $fileView; ?>
			</td>
		</tr>
	<?php } ?>
	<tr>
		<td class="label"><label><?php echo $attributeLabels['associationType']; ?></label></td>
		<td colspan="3">
			<?php 
				if(isset($model->associationId) && $model->associationId != null) {
					$association = X2Model::getAssociationModel($model->associationType,$model->associationId);
					echo CHtml::link($association->name,array($model->associationType.'/view','id'=>$model->associationId));
				}
			?>
		</td>
	</tr>
	<tr>
		<td class="label" width="20%"><label><?php echo $attributeLabels['uploadedBy']; ?></label></td>
		<td width="25%"><?php echo User::getUserLinks($model->uploadedBy); ?></td>
		<td class="label" width="15%"><label><?php echo $attributeLabels['private']; ?></label></td>
		<td><b><?php echo CHtml::checkBox('private', $model->private, array('onclick'=>'return false;', 'onkeydown'=>'return false;')); ?></td>
	</tr>
	<tr>
		<td class="label" width="15%"><label><?php echo $attributeLabels['createDate']; ?></label></td>
		<td><b><?php echo Formatter::formatLongDateTime($model->createDate); ?></td>
		<td class="label" width="15%"><label><?php echo $attributeLabels['lastUpdated']; ?></label></td>
		<td><b><?php echo Formatter::formatLongDateTime($model->lastUpdated); ?></td>
	</tr>
</table>
</div>
<?php echo CHtml::link('Download file',array('download','id'=>$model->id),array('class'=>'x2-button btn btn-mini  btn-yellow')); ?>
<?php /* if($file_ext == 'pdf') { ?>
<div class="form">
	<iframe width="565" height="550" src="<?php echo Yii::app()->request->baseUrl.'/uploads/'.urlencode($model->fileName); ?>">
</div>
<?php }  */
 ?>